package com.iamteer.servlet;

import java.util.Date;
import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.iamteer.entity.DinnerTable;

@WebServlet("/table")
public class DinnerTableServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

	public Object add(HttpServletRequest request, HttpServletResponse response) {
		String tName = request.getParameter("tName");
		DinnerTable dt = new DinnerTable();
		dt.settName(tName);
		dinnerTableService.add(dt);
		return request.getRequestDispatcher("/table?method=list");
	}
	
	public Object delete(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		dinnerTableService.delete(Integer.parseInt(id));
		return request.getRequestDispatcher("/table?method=list");
	}
	
	public Object book(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		dinnerTableService.book(Integer.parseInt(id), new Date());
		return request.getRequestDispatcher("/table?method=list");
	}
	
	public Object cancel(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		dinnerTableService.cancel(Integer.parseInt(id));
		return request.getRequestDispatcher("/table?method=list");
	}
	
	public Object list(HttpServletRequest request, HttpServletResponse response) {
		List<DinnerTable> list = dinnerTableService.query();
		request.setAttribute("tableList", list);
		return request.getRequestDispatcher("/sys/table/tableList.jsp");
	}
	
}
